package com.yykj.hospital.server.controller;

import com.yykj.bank.client.dto.BankInfoDTO;
import com.yykj.bank.client.feign.BankFeignClient;
import com.yykj.common.vo.ResultVO;
import com.yykj.hospital.server.dto.bank.BankListDTO;
import com.yykj.hospital.server.form.bank.BindCardInfoForm;
import com.yykj.hospital.server.service.bank.BankService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/api/doctor/bank")
@SuppressWarnings("unchecked")
@Api(tags = "银行卡相关接口")
public class DoctorBankController {

    @ApiOperation("可用银行卡列表")
    @GetMapping("/available/list")
    public ResultVO<List<BankInfoDTO>> listAvailableBank() {
        return ResultVO.success(bankFeignClient.listAvailableBank());
    }

    @ApiOperation("绑定银行卡到医生账号")
    @PostMapping("/bind")
    public ResultVO bindCardToDoctor(@RequestBody @Valid BindCardInfoForm infoForm) {
        bankService.bindCardToDoctor(infoForm);
        return ResultVO.success();
    }

    @ApiOperation("已经绑定银行卡列表")
    @GetMapping("/bind/list/{doctorId}")
    public ResultVO<List<BankListDTO>> listDoctorBankCard(@PathVariable(name = "doctorId") String doctorId){
        return ResultVO.success(bankService.listDoctorBankCard(doctorId));
    }

    @ApiOperation("解绑银行卡号")
    @DeleteMapping("/bind/delete/{id}")
    public ResultVO<List<BankListDTO>> listDoctorBankCard(@PathVariable(name = "id") Integer id){
        bankService.deleteBindCard(id);
        return ResultVO.success();
    }


    private BankService bankService;

    private BankFeignClient bankFeignClient;

    @Autowired
    public void setBankService(BankService bankService) {
        this.bankService = bankService;
    }

    @Autowired
    public void setBankFeignClient(BankFeignClient bankFeignClient) {
        this.bankFeignClient = bankFeignClient;
    }
}
